$("#getRecord").click(e => {
    chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        chrome.tabs.executeScript(tabs[0].id,
            {
                code: 'calcOvertimeHours()',
            }, function (results) {
                results.map(function (item) {
                    generateTable(item);
                })
            });
    });
});

function generateTable(list) {
    let table = "<table  class='gridtable'><tr class='title'><th>序 号</th><th>姓 名</th><th>加班日期</th><th>休息标志</th><th>加班时间</th><th>加班时长</th><th>加班餐补贴</th><th>备 注</th></tr>";
    let sumOverTime = 0;
    let sumMeals = 0;
    let idx = 0;
    list.map(item => {
        idx++;
        sumOverTime += item.overTime;
        sumMeals += item.meals;
        table += "<tr><td>" + idx + "</td><td>" + item.name + "</td><td>" + item.date.replace(/-/g, '/') + "</td><td>" + item.rest + "</td><td>" + item.beginOverTime + "-" + item.endOverTime + "</td><td>" + item.overTime + "</td><td>" + (item.meals === 0 ? '' : item.meals) + "</td><td>" + item.note + "</td></tr>";
    });
    table += "</table>";
    $('#overtime_table').html(table);
    if (sumOverTime > 0) {
        $('.sumOvertime').removeClass("gone");
        $('.sumOvertime').text("累计加班时长：" + sumOverTime + "小时  餐费补贴：" + sumMeals + "元");
    }
}